<%@ include file="/html/portlet/users_admin/init.jsp" %>

<%
User selUser = (User)request.getAttribute("user.selUser");
Contact selContact = (Contact)request.getAttribute("user.selContact");
%>

<liferay-ui:error-marker key="errorSection" value="details" />

<aui:model-context bean="<%= selUser %>" model="<%= User.class %>" />

<h3><liferay-ui:message key="details" /></h3>

<aui:fieldset column="<%= true %>" cssClass="aui-w50">
    <liferay-ui:success key="verificationEmailSent" message="your-email-verification-code-has-been-sent-and-the-new-email-address-will-be-applied-to-your-account-once-it-has-been-verified" />

    <liferay-ui:error exception="<%= DuplicateUserScreenNameException.class %>" message="the-screen-name-you-requested-is-already-taken" />

    <liferay-ui:error exception="<%= GroupFriendlyURLException.class %>">

        <%
        GroupFriendlyURLException gfurle = (GroupFriendlyURLException)errorException;
        %>

        <c:if test="<%= gfurle.getType() == GroupFriendlyURLException.DUPLICATE %>">
            <liferay-ui:message key="the-screen-name-you-requested-is-associated-with-an-existing-friendly-url" />
        </c:if>
    </liferay-ui:error>

    <liferay-ui:error exception="<%= ReservedUserScreenNameException.class %>" message="the-screen-name-you-requested-is-reserved" />
    <liferay-ui:error exception="<%= UserScreenNameException.class %>" message="please-enter-a-valid-screen-name" />

    <c:if test="<%= !PrefsPropsUtil.getBoolean(company.getCompanyId(), PropsKeys.USERS_SCREEN_NAME_ALWAYS_AUTOGENERATE) || (selUser != null) %>">
        <c:choose>
            <c:when test="<%= PrefsPropsUtil.getBoolean(company.getCompanyId(), PropsKeys.USERS_SCREEN_NAME_ALWAYS_AUTOGENERATE) || ((selUser != null) && !UsersAdminUtil.hasUpdateScreenName(permissionChecker, selUser)) %>">
                <aui:field-wrapper name="screenName">
                    <%= selUser.getScreenName() %>

                    <aui:input name="screenName" type="hidden" value="<%= selUser.getScreenName() %>" />
                </aui:field-wrapper>
            </c:when>
            <c:otherwise>
                <aui:input name="screenName" />
            </c:otherwise>
        </c:choose>
    </c:if>

    <liferay-ui:error exception="<%= DuplicateUserEmailAddressException.class %>" message="the-email-address-you-requested-is-already-taken" />
    <liferay-ui:error exception="<%= ReservedUserEmailAddressException.class %>" message="the-email-address-you-requested-is-reserved" />
    <liferay-ui:error exception="<%= UserEmailAddressException.class %>" message="please-enter-a-valid-email-address" />

    <c:choose>
        <c:when test="<%= (selUser != null) && !UsersAdminUtil.hasUpdateEmailAddress(permissionChecker, selUser) %>">
            <aui:field-wrapper name="emailAddress">
                <%= selUser.getDisplayEmailAddress() %>

                <aui:input name="emailAddress" type="hidden" value="<%= selUser.getEmailAddress() %>" />
            </aui:field-wrapper>
        </c:when>
        <c:otherwise>

            <%
            User displayEmailAddressUser = null;

            if (selUser != null) {
                displayEmailAddressUser = (User)selUser.clone();

                displayEmailAddressUser.setEmailAddress(displayEmailAddressUser.getDisplayEmailAddress());
            }
            %>

            <aui:input bean="<%= displayEmailAddressUser %>" model="<%= User.class %>" name="emailAddress">
                <c:if test="<%= PrefsPropsUtil.getBoolean(company.getCompanyId(), PropsKeys.USERS_EMAIL_ADDRESS_REQUIRED) %>">
                    <aui:validator name="required" />
                </c:if>
            </aui:input>
        </c:otherwise>
    </c:choose>

    <liferay-ui:error exception="<%= ContactFirstNameException.class %>" message="please-enter-a-valid-first-name" />
    <liferay-ui:error exception="<%= ContactFullNameException.class %>" message="please-enter-a-valid-first-middle-and-last-name" />

    <aui:input name="firstName" />

    <liferay-ui:error exception="<%= ContactLastNameException.class %>" message="please-enter-a-valid-last-name" />

    <aui:input name="lastName">
        <c:if test="<%= PrefsPropsUtil.getBoolean(company.getCompanyId(), PropsKeys.USERS_LAST_NAME_REQUIRED, PropsValues.USERS_LAST_NAME_REQUIRED) %>">
            <aui:validator name="required" />
        </c:if>
    </aui:input>
</aui:fieldset>